<template>
  <el-calendar v-if="show" v-model="currentDate">
    <template #dateCell="{ date, data }">
      <div class="date-content">
        <!-- date 日期对象 data 天的数据 年-月-日 -->
        <span class="text">{{ formatDay(data.day) }}</span>
        <!-- 如果是周六，周日显示休 -->
        <span v-if="isWeek(date)" class="rest">休</span>
      </div>
    </template>
  </el-calendar>
</template>

<script>
export default {
  data () {
    return {
      show: true,
      currentDate: new Date()
    }
  },
  watch: {
    async '$i18n.locale' (newValue) {
      console.log(newValue)
      this.show = false
      await this.$nextTick()
      this.show = true
    }
  },
  methods: {
    formatDay (time) {
      // console.log(time)
      return time.split('-')[2]
    },
    // 判断是否是周六或周日
    // 当是6和0时，返回的数据是true,就会显示是休
    isWeek (date) {
      return date.getDay() === 6 || date.getDay() === 0
    }
  }
}
</script>

<style lang="scss" scoped>
::v-deep .el-calendar-day {
  height: 50px;
}
.date-content {
  height: 40px;
  text-align: center;
  line-height: 40px;
  font-size: 14px;
}
// 休息时间
.date-content .rest {
  color: #fff;
  border-radius: 50%;
  background: rgb(250, 124, 77);
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
  font-size: 12px;
  margin-left: 10px;
}
.date-content .text {
  width: 20px;
  height: 20px;
  line-height: 20px;
  display: inline-block;
}
// 当前日期
::v-deep .el-calendar-table td.is-selected .text {
  background: #409eff;
  color: #fff;
  border-radius: 50%;
}
</style>
